package cn.edu.sdjzu.xg.eagle.mapper;

import cn.edu.sdjzu.xg.eagle.entities.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {

    @Select("SELECT StudentID, Name, Level, Position, Gender, `Class`, College, ContactInfo, PhotoID, Password FROM student WHERE StudentID = #{studentId}")
    @Results({
            @Result(property = "studentId", column = "StudentID"),
            @Result(property = "name", column = "Name"),
            @Result(property = "level", column = "Level"),
            @Result(property = "position", column = "Position"),
            @Result(property = "gender", column = "Gender"),
            @Result(property = "classInfo", column = "Class"),
            @Result(property = "college", column = "College"),
            @Result(property = "contactInfo", column = "ContactInfo"),
            @Result(property = "photoId", column = "PhotoID"),
            @Result(property = "password", column = "Password")
    })
    Student getStudentById(Integer studentId);

    @Select("SELECT StudentID, Name, Level, Position, Gender, `Class`, College, ContactInfo, PhotoID, Password FROM student")
    @Results({
            @Result(property = "studentId", column = "StudentID"),
            @Result(property = "name", column = "Name"),
            @Result(property = "level", column = "Level"),
            @Result(property = "position", column = "Position"),
            @Result(property = "gender", column = "Gender"),
            @Result(property = "classInfo", column = "Class"),
            @Result(property = "college", column = "College"),
            @Result(property = "contactInfo", column = "ContactInfo"),
            @Result(property = "photoId", column = "PhotoID"),
            @Result(property = "password", column = "Password")
    })
    List<Student> getStudents();

    @Insert("INSERT INTO Student (Name, Level, Position, Gender, `Class`, College, ContactInfo, PhotoID, Password) VALUES (#{name}, #{level}, #{position}, #{gender}, #{classInfo}, #{college}, #{contactInfo}, #{photoId}, #{password})")
    @Options(useGeneratedKeys = true, keyProperty = "studentId")
    boolean addStudent(Student student);

    @Update("UPDATE Student SET Name = #{name}, Level = #{level}, Position = #{position}, Gender = #{gender}, `Class` = #{classInfo}, College = #{college}, ContactInfo = #{contactInfo}, PhotoID = #{photoId}, Password = #{password} WHERE StudentID = #{studentId}")
    boolean updateStudent(Student student);

    @Delete("DELETE FROM Student WHERE StudentID = #{studentId}")
    boolean deleteStudent(Integer studentId);
}